package com.lihua.newideas.controller;

import com.lihua.newideas.pojo.MyUser;
import com.lihua.newideas.service.impl.MyUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//登录
@Controller
public class LoginController {

    @Autowired
    MyUserServiceImpl userServiceImple;

    //注册
    @PostMapping("/regSubmit")
    @ResponseBody
    public  String regSubmit(MyUser user){
        System.out.println(user.toString());
        if(!user.getUserName().equals("")&&!user.getUserName().equals("")){
            if (userServiceImple.insertUser(user)!=null){
                return user.getUserName()+"注册成功";
            }else {
                return "用户已存在";
            }
        }else {
            return "账号密码不能为空";
        }
    }
    //修改密码
    @PostMapping("/updatePassWord")
    @ResponseBody
    public String updatePassWord(MyUser user){
        System.out.println(user.toString());
        String s = userServiceImple.updateUserByUserName(user.getPassWord(), user.getUserName(), user.getCode());
        return s;
    }
}
